package com.fyt.reachgo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fyt.reachgo.config.RabbitMQConfig;
import com.fyt.reachgo.domain.Result;
import com.fyt.reachgo.domain.TravelGuide;
import com.fyt.reachgo.domain.UserDisinterest;
import com.fyt.reachgo.domain.UserLike;
import com.fyt.reachgo.service.UserDisinterestService;
import com.fyt.reachgo.mapper.UserDisinterestMapper;
import com.fyt.reachgo.utils.UserHolder;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
* @author 27675
* @description 针对表【user_disinterest(用户不感兴趣路书记录表)】的数据库操作Service实现
* @createDate 2025-04-09 10:47:24
*/
@Service
@Slf4j
@RequiredArgsConstructor
public class UserDisinterestServiceImpl extends ServiceImpl<UserDisinterestMapper, UserDisinterest>
    implements UserDisinterestService{

    private final RabbitTemplate rabbitTemplate;

    /**
     * 不感兴趣
     * @param userDisinterest
     * @return
     */
    @Override
    public Result userUnLike(UserDisinterest userDisinterest) {

        if (userDisinterest.getTravelGuideId() != null) {// 正确传参
            // 设置当前用户ID和操作时间
            userDisinterest.setCreateTime(LocalDateTime.now());
            userDisinterest.setUserId(UserHolder.getUser().getUserId());
            // 发送消息到RabbitMQ做异步操作
            rabbitTemplate.convertAndSend(
                    RabbitMQConfig.USER_DISINTEREST_EXCHANGE,
                    RabbitMQConfig.USER_DISINTEREST_ROUTING_KEY,
                    userDisinterest
            );

            return Result.success();
        }
        return Result.error("参数错误");
    }

}




